#ifndef _CPARTICLES_H
#define _CPARTICLES_H

#define GL_GLEXT_PROTOTYPES

#include "texture.h"
#include "entity.h"
#include "physics.h"
#include <GL/glext.h>


#include <math.h>
#include <list>

using namespace std;

const int MAX_PARTICLES = 100000;
const int Z_BACK =  0.5;
const int Z_0 =     0;
const int Z_FRONT = -0.5;


// ---------------------------
// EParticlesType
// Types of particles.
// --------------------------- 
typedef enum 
{
	PART_EXPLOSION,
	PART_FIRE,
	PART_AURA
} EParticlesType;


// -----------------------------------------------------------------------------
// TParticle
// Description for every particle in our particle system.
// -----------------------------------------------------------------------------
typedef struct
{
  bool  bActive;
  float fLife;
  float fFade; 
  float fGravityAcel;

  // Color
  float fR;  
  float fG;
  float fB;
  float fColor[3];

  // Particle Coords
  float fPosition[3];
  float fX;
  float fY;
  float fZ;

  // Vector de Movimiento/Direccion
  float fVelocity[3];
  float fXd;
  float fYd;
  float fZd;
  
  Physics particle_physics;
          
} TParticle;

//------------------------------------------------------------------------------
// Particles 
// Implements a particle system.   
//------------------------------------------------------------------------------
class Particles: public Entity
{
	private:
 		Log  *m_pLog;
  		Texture *m_pTexture;
  		std::list<TParticle *> m_particles;
  
		EParticlesType m_eType;  
		float m_fGravity;    
		float m_fXAcel;
		float m_fInitialLife; 
		float m_fRatio;
		float m_fParticleSize;
		int   m_iAliveParticles;
		int   m_iNumParticles;    
		bool  m_bRotate;
	  
		// Private methods
		void particleDraw(TParticle *_particle);
  		void particleReset(TParticle *_particle);
		void particleUpdate(TParticle *_particle);
  
 	public:

		Particles();
		~Particles();
		bool init(Texture *_texture,int _numParticles,EParticlesType _type,float _life,float _gravity,float _X,float _Y,float _Z,float _colorR,float _colorG,float _colorB);
  		void freeMemory();
  		void draw();
		void draw2();
  		void update();
  		bool getAlive();

	  //---------------------------------
	  // Get functions (inline)
	  //---------------------------------

	  //---------------------------------
	  //Set functions (inline)
	  //---------------------------------
  		inline void setRotate(bool bRotate)   		{m_bRotate=bRotate;}
  		inline void setLife(float fLife)          	{m_fInitialLife=fLife;}
  		inline void setGravity(float fGravity)    	{m_fGravity=fGravity;}
  		inline void setTexture(Texture *pTexture)	{m_pTexture=pTexture;}
  		inline void setNumParticles(int iNumParticles)		{m_iNumParticles=iNumParticles;}
		inline void setParticleSize(float _fParticleSize)	{m_fParticleSize=_fParticleSize;}
  		inline void setRatio(float fRatio)    {m_fRatio=fRatio;}
  		inline void setXAcel(float fAcelX)    {m_fXAcel=fAcelX;}
};

#endif
